package com.fight.strive.sys.modules.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * return status 返回或响应的状态
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ReStatus<T> implements Serializable {

    /**
     * 状态，success,fail,perm,login
     * 200: 接口返回成功
     * 500: 接口返回失败
     * 401: token有效，接口无访问权限
     * 403：未登录，或token无效
     */
    private Integer status;

    /**
     * 响应描述
     */
    private String msg;

    /**
     * 数据对象
     */
    private T data;

    public static <T> ReStatus<T> success() {
        return new ReStatus<>(
                200, "操作成功", null);
    }

    public static <T> ReStatus<T> success(T data) {
        return new ReStatus<>(
                200, "操作成功", data);
    }

    public static <T> ReStatus<T> failure() {
        return new ReStatus<>(
                500, "操作失败", null);
    }

    public static <T> ReStatus<T> failure(String msg) {
        return new ReStatus<>(
                500, msg, null);
    }

    public static <T> ReStatus<T> accessDenied() {
        return new ReStatus<>(
                401, "无访问权限", null);
    }

    public static <T> ReStatus<T> invalidToken() {
        return new ReStatus<>(
                403, "用户未登录，请先登录！", null);
    }
}
